from typing import *


class Solution:

    def singleNumber(self, nums: List[int]) -> int:
        ans = 0
        for i in range(32):
            f = 1 << i
            c = 0
            for num in nums:
                if num & f != 0:
                    c += 1
            if c % 3 != 0:
                ans = f | ans if i < 31 else ans - f
        return ans
